/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package bean;

/**
 *
 * @author alessandro
 */
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.faces.bean.ApplicationScoped;
import javax.faces.bean.ManagedBean;
import other.TextModel;

@ManagedBean(name="messageBean")
@ApplicationScoped
public class MessageBean implements Serializable {
	private static final int MAX_SIZE = 40;

	private List<TextModel> textList = new ArrayList<TextModel>(0);

	public MessageBean() {
	}

	public List<TextModel> getTextList() {
		return textList;
	}

	public void setTextList(List<TextModel> textList) {
		this.textList = textList;
	}

	public void addToList(String user, String message) {
                if(!(message.equals("")))
                    textList.add(makeTextModel(user, message));

		if (textList.size() > MAX_SIZE) {
                   
			textList.remove(0);
                        textList.remove(1);
		}
	}

	private TextModel makeTextModel(String user, String message) {
		return new TextModel(user + ": " + message, message);
	}
}
